home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / SCIENTIF / 0807.ZIP / SYNCSAT.BAS < prev    next >
BASIC Source File  |  1987-10-01  |  9KB  |  351 lines

  1. ' Program "SYNCSAT"
  2.  
  3. ' Copyright (C) 1982 by David Eagle
  4.  
  5. ' IBM-PC  << QuickBASIC Compiler Version 2.0 >>
  6.  
  7. ' Public domain for the IBM-PC on October 8, 1986
  8.  
  9. ' computes direction of geosynchronous satellites
  10.  
  11. ' azimuth angle; positive clockwise from north ( degrees )
  12. ' elevation angle; positive above the horizon ( degrees )
  13.  
  14. '**********************************************************
  15.  
  16. DEFDBL A-Z
  17. OPTION BASE 1
  18.  
  19. CONST RREQ=1D0/637814D0
  20. CONST FLAT=1D0/298.257D0
  21. CONST PI=3.14159265D0
  22. CONST PIDIV2=.5D0*PI
  23. CONST HGEO=6.6107426D0
  24. CONST DTR=PI/180D0
  25. CONST RTD=180D0/PI
  26.  
  27. DIM SHARED LV(3),UP(3),MATRIX(3,3)
  28.  
  29. COMMON SHARED OBSLAT,OBSLONG,OBSALT,XOBS,YOBS,ZOBS
  30. COMMON SHARED AZIMUTH,ELEVATION
  31.  
  32. CLS
  33. PRINT
  34. PRINT
  35. PRINT "Program SYNCSAT"
  36. PRINT "(C) Copyright 1982 by David Eagle"
  37. PRINT
  38. PRINT "Microsoft QuickBASIC Compiler"
  39. PRINT "(C) Copyright Microsoft Corp. 1982-1987"
  40. PRINT
  41. CALL KEYCHECK
  42.  
  43. CLS
  44. PRINT
  45. PRINT
  46. PRINT "Program introduction ( y = yes, n = no )"
  47. INPUT intro$
  48. IF INSTR("yY",intro$) THEN CALL INTRODUCTION
  49.  
  50. MAIN:
  51. CLS
  52. PRINT
  53. PRINT
  54. PRINT TAB(16);"Program SYNCSAT"
  55. LOCATION:
  56. PRINT
  57. PRINT
  58. PRINT "Observer latitude ( degrees [ - 90 to + 90 ] )"
  59. PRINT "< north latitudes are positive, south latitudes are negative >"
  60. INPUT OBSLAT
  61. PRINT
  62. PRINT "Observer west longitude ( degrees [ 0 - 360 ] )"
  63. INPUT OBSLONG
  64. PRINT
  65. PRINT "Observer altitude ( meters )"
  66. PRINT "< positive above sea level, negative below sea level >"
  67. INPUT OBSALT
  68. SATELLITE:
  69. PRINT
  70. PRINT "Satellite west longitude ( degrees [ 0 - 360 ] )"
  71. INPUT SATLONG
  72.  
  73. ' calculate observer's position
  74.  
  75. CALL OBSVECTOR
  76.  
  77. ' calculate satellite's position
  78.  
  79. A=-SATLONG*DTR
  80. XSAT=HGEO*COS(A)
  81. YSAT=HGEO*SIN(A)
  82.  
  83. ' calculate pointing angles to satellite
  84.  
  85. X3=XSAT-XOBS
  86. Y3=YSAT-YOBS
  87. Z3=-ZOBS
  88.  
  89. R=SQR(X3^2+Y3^2+Z3^2)
  90.  
  91. UP(1)=X3/R
  92. UP(2)=Y3/R
  93. UP(3)=Z3/R
  94.  
  95. CALL TOPOCENTRIC
  96.  
  97. ' print results
  98.  
  99. FORMAT$="####.###"
  100.  
  101. CLS
  102. PRINT
  103. PRINT
  104. PRINT TAB(28);"Program SYNCSAT"
  105. PRINT
  106. PRINT
  107. PRINT
  108. PRINT TAB(5);"Observer latitude         ( degrees )";
  109. PRINT USING FORMAT$;TAB(50);OBSLAT
  110. PRINT
  111. PRINT TAB(5);"Observer west longitude   ( degrees )";
  112. PRINT USING FORMAT$;TAB(50);OBSLONG
  113. PRINT
  114. PRINT TAB(5);"Observer altitude         ( meters )";
  115. PRINT USING FORMAT$;TAB(50);OBSALT
  116. PRINT
  117. PRINT
  118. PRINT TAB(5);"Azimuth                   ( degrees )";
  119. PRINT USING FORMAT$;TAB(50);AZIMUTH
  120. PRINT
  121. PRINT TAB(5);"Elevation                 ( degrees )";
  122. PRINT USING FORMAT$;TAB(50);ELEVATION
  123. PRINT
  124. PRINT
  125. PRINT TAB(5);"Satellite west longitude  ( degrees )";
  126. PRINT USING FORMAT$;TAB(50);SATLONG
  127. PRINT
  128. CALL KEYCHECK
  129.  
  130. ' request another selection
  131.  
  132. CLS
  133. PRINT
  134. PRINT
  135. PRINT "Another selection ( y = yes, n = no )"
  136. INPUT REPLY$
  137. IF INSTR("nN",REPLY$) THEN END
  138. PRINT
  139. PRINT "Another location ( y = yes, n = no )"
  140. INPUT REPLY$
  141. IF INSTR("yY",REPLY$) THEN GOTO LOCATION
  142. PRINT
  143. PRINT "Another satellite ( y = yes, n = no )"
  144. INPUT REPLY$
  145. IF INSTR("yY",REPLY$) THEN GOTO SATELLITE
  146. GOTO MAIN
  147.  
  148. END
  149.  
  150. '***************************************************************
  151.  
  152. SUB OBSVECTOR STATIC
  153.  
  154.   ' observer position vector subroutine
  155.  
  156.   A=OBSLAT*DTR
  157.   B=SIN(A)
  158.   C=COS(A)
  159.   D=1D0-FLAT
  160.   E=SQR(1D0-(2D0*FLAT-FLAT^2)*B^2)
  161.   F=1D0/E+OBSALT*RREQ
  162.   G=D^2/E+OBSALT*RREQ
  163.   H=-OBSLONG*DTR
  164.   XOBS=F*C*COS(H)
  165.   YOBS=F*C*SIN(H)
  166.   ZOBS=G*B
  167.  
  168. END SUB
  169.  
  170. '***************************************************************
  171.  
  172. SUB TOPOCENTRIC STATIC
  173.  
  174.   ' eci to topocentric subroutine
  175.  
  176.   A=SIN(OBSLAT*DTR)
  177.   B=COS(OBSLAT*DTR)
  178.   C=SIN(-OBSLONG*DTR)
  179.   D=COS(-OBSLONG*DTR)
  180.   MATRIX(1,1)=A*D
  181.   MATRIX(1,2)=A*C
  182.   MATRIX(1,3)=-B
  183.   MATRIX(2,1)=-C
  184.   MATRIX(2,2)=D
  185.   MATRIX(2,3)=0D0
  186.   MATRIX(3,1)=B*D
  187.   MATRIX(3,2)=B*C
  188.   MATRIX(3,3)=A
  189.  
  190.   FOR I%=1 TO 3
  191.     A=0D0
  192.     FOR J%=1 TO 3
  193.       A=A+MATRIX(I%,J%)*UP(J%)
  194.     NEXT J%
  195.     LV(I%)=A
  196.   NEXT I%
  197.  
  198.   IF ABS(LV(3))>1D0 THEN
  199.     ELEVATION=SGN(LV(3))*90D0
  200.   ELSE
  201.     ELEVATION=(ATN(LV(3)/SQR(1D0-LV(3)^2)))*RTD
  202.   END IF
  203.  
  204.   A=LV(2)
  205.   B=-LV(1)
  206.   CALL ATAN3(A,B,C)
  207.   AZIMUTH=RTD*C
  208.  
  209. END SUB
  210.  
  211. '***************************************************************
  212.  
  213. SUB ATAN3(A,B,C) STATIC
  214.  
  215.   ' 4-quadrant arc tangent subroutine
  216.  
  217.   IF ABS(A)<1D-08 THEN
  218.     C=(1-SGN(B))*PIDIV2
  219.     EXIT SUB
  220.   ELSE
  221.     C=(2-SGN(A))*PIDIV2
  222.   END IF
  223.   IF ABS(B)<1D-08 THEN
  224.     EXIT SUB
  225.   ELSE
  226.     C=C+SGN(A)*SGN(B)*(ABS(ATN(A/B))-PIDIV2)
  227.   END IF
  228.  
  229. END SUB
  230.  
  231. '***************************************************************
  232.  
  233. SUB KEYCHECK STATIC
  234.  
  235.   ' check user response subroutine
  236.  
  237.   PRINT
  238.   PRINT
  239.   PRINT TAB(20);"< press any key to continue >";
  240.  
  241.   A$=""
  242.   WHILE A$=""
  243.     A$=INKEY$
  244.   WEND
  245.  
  246. END SUB
  247.  
  248. '***************************************************************
  249.  
  250. SUB INTRODUCTION STATIC
  251.  
  252.   ' program introduction subroutine
  253.  
  254.   CLS
  255.   PRINT TAB(15);"    Program 'SYNCSAT' is an interactive"
  256.   PRINT TAB(15);"BASIC computer program which can be"
  257.   PRINT TAB(15);"used to determine both the azimuth and"
  258.   PRINT TAB(15);"elevation pointing angles from an earth"
  259.   PRINT TAB(15);"observer anywhere in the world to a"
  260.   PRINT TAB(15);"geosynchronous satellite. The software"
  261.   PRINT TAB(15);"in this program takes into account the"
  262.   PRINT TAB(15);"effect of the flattening or 'oblateness'"
  263.   PRINT TAB(15);"of the earth on the observer location"
  264.   PRINT TAB(15);"on the earth. It also compensates for"
  265.   PRINT TAB(15);"'non-sea level' observation and antenna"
  266.   PRINT TAB(15);"sites. These features provide the user"
  267.   PRINT TAB(15);"with very accurate pointing angles."
  268.   PRINT
  269.   PRINT TAB(15);"     USER INPUTS AND SELECTIONS"
  270.   PRINT
  271.   PRINT TAB(15);"   Program SYNCSAT will prompt the user"
  272.   PRINT TAB(15);"for several inputs necessary for the"
  273.   PRINT TAB(15);"software to work properly. This is a"
  274.   PRINT TAB(15);"description of these requests and a"
  275.   PRINT TAB(15);"discussion of the proper user response."
  276.   CALL KEYCHECK
  277.  
  278.   CLS
  279.   PRINT TAB(15);"    Observer latitude ( degrees )"
  280.   PRINT
  281.   PRINT TAB(15);"The user should respond with his or her"
  282.   PRINT TAB(15);"geographic latitude in decimal degrees"
  283.   PRINT TAB(15);"taking note of the sign convention. For"
  284.   PRINT TAB(15);"example, an observer at 42 degrees, 30"
  285.   PRINT TAB(15);"minutes north latitude would input 42.5."
  286.   PRINT
  287.   PRINT TAB(15);"    Observer west longitude ( degrees )"
  288.   PRINT
  289.   PRINT TAB(15);"The proper response here will be the"
  290.   PRINT TAB(15);"observer's west longitude in decimal"
  291.   PRINT TAB(15);"degrees. West longitude equals 360"
  292.   PRINT TAB(15);"degrees minus east longitude."
  293.   PRINT
  294.   PRINT TAB(15);"    Observer altitude ( meters )"
  295.   PRINT
  296.   PRINT TAB(15);"At this point the user should input the"
  297.   PRINT TAB(15);"altitude at his or her location in the"
  298.   PRINT TAB(15);"units of meters. Sites above sea level"
  299.   PRINT TAB(15);"are input as positive numbers and those"
  300.   PRINT TAB(15);"below sea level are negative numbers."
  301.   CALL KEYCHECK
  302.  
  303.   CLS
  304.   PRINT TAB(15);"   Satellite west longitude ( degrees )"
  305.   PRINT
  306.   PRINT TAB(15);"The user should respond with the west"
  307.   PRINT TAB(15);"longitude of the satellite of interest."
  308.   PRINT TAB(15);"This number is input in decimal degrees."
  309.   PRINT TAB(15);" After the program has run, it will ask"
  310.   PRINT TAB(15);"the user for another selection. A user"
  311.   PRINT TAB(15);"should respond with 'y' if he or she"
  312.   PRINT TAB(15);"desires the selection or 'n' if not."
  313.   PRINT
  314.   PRINT TAB(15);"    Another selection ( y = yes, n = no ) ?"
  315.   PRINT
  316.   PRINT TAB(15);"A user response of 'n' will exit the"
  317.   PRINT TAB(15);"'SYNCSAT' program."
  318.   PRINT
  319.   PRINT TAB(15);"    Another location ( y = yes, n = no ) ?"
  320.   PRINT
  321.   PRINT TAB(15);"The user should respond with 'y' to"
  322.   PRINT TAB(15);"compute the location of a satellite"
  323.   PRINT TAB(15);"relative to another geographic location."
  324.   CALL KEYCHECK
  325.  
  326.   CLS
  327.   PRINT TAB(15);"     Another satellite ( y = yes, n = no ) ?"
  328.   PRINT
  329.   PRINT TAB(15);"The user should respond with 'y' to"
  330.   PRINT TAB(15);"compute the pointing angles to another"
  331.   PRINT TAB(15);"geosynchronous satellite."
  332.   PRINT
  333.   PRINT TAB(15);"          PROGRAM OUTPUT"
  334.   PRINT
  335.   PRINT TAB(15);"Program 'SYNCSAT' outputs the observer-"
  336.   PRINT TAB(15);"centered or 'topocentric' azimuth and"
  337.   PRINT TAB(15);"elevation angles from an observer to a"
  338.   PRINT TAB(15);"geosynchronous satellite. Azimuth is"
  339.   PRINT TAB(15);"measured positive clockwise from north"
  340.   PRINT TAB(15);"and elevation is positive above the"
  341.   PRINT TAB(15);"observer's horizon. For example, an"
  342.   PRINT TAB(15);"azimuth angle of 90 degrees is east and"
  343.   PRINT TAB(15);"180 degrees is south, etc. Elevation"
  344.   PRINT TAB(15);"angles which are negative indicate that"
  345.   PRINT TAB(15);"the satellite cannot be seen from an"
  346.   PRINT TAB(15);"observer's location. Both angles are"
  347.   PRINT TAB(15);"printed in decimal degrees."
  348.   CALL KEYCHECK
  349.  
  350. END SUB
  351.